namespace GemBox.Spreadsheet
{
    using System;

    internal class FunctionVarFormulaToken : FormulaToken
    {
        private byte argumentsCount;
        private FormulaFunctionInfo function;

        public FunctionVarFormulaToken(FormulaTokenCode code) : base(code, 4, FormulaTokenType.Function)
        {
        }

        public override byte[] ConvertToBytes()
        {
            byte[] array = base.ConvertToBytes();
            array[1] = this.argumentsCount;
            BitConverter.GetBytes(this.function.Code).CopyTo(array, 2);
            return array;
        }

        public override void DelayInitialize(object[] data)
        {
            this.function = FormulaFunctionsTable.Instance[data[0] as string];
            this.argumentsCount = (byte) data[1];
        }

        public override void Read(byte[] rpnBytes, int startIndex)
        {
            this.argumentsCount = rpnBytes[startIndex];
            ushort num = BitConverter.ToUInt16(rpnBytes, startIndex + 1);
            this.function = FormulaFunctionsTable.Instance[num];
        }

        public override string ToString()
        {
            return this.function.Name.ToUpper();
        }

        public byte ArgumentsCount
        {
            get
            {
                return this.argumentsCount;
            }
        }

        public FormulaFunctionInfo Function
        {
            get
            {
                return this.function;
            }
        }
    }
}
